package Parking;

import java.util.Date;
import java.util.Scanner;

public class CarApplication {
	
	private static final int[] location = new int[100];

	CarArray cararray=new CarArray();
	public  String  getin(String  s) {
		
	   
	    if(cararray.carlist.size()==100) {
	    
	    	return "对不起，车位已满";
	    }
		for(int i=0;i<cararray.carlist.size();i++) {
			if(s.equals(cararray.carlist.get(i).getCardnum())) {
				return  "该车已在车库"+"    该车停在"+cararray.carlist.get(i).getLocationnum()+"位";
			}
		}
	    
	    
	    Car car=new Car();
	
		String st=s;
		car.setCardnum(st);
		for(int i=0;i<100;i++) {
			if(location[i]==0) {
			car.setLocationnum("ss"+i);
				location[i]=1;
				break;
			}
		}
		cararray.goin(car);
	
		return   "已成功停入"+'\n'
		+"      入库时间为:"+car.getIntime().getDate()+'\n'
		+"      你的车位号为"+car.getLocationnum()+'\n'
		+"      剩余空闲车位数："+(100-cararray.carlist.size());
		
	}
	public String  getout(String s) {
	
		String st=s;
		Car car=new Car();
		boolean flag =false;
		for(int i=0;i<cararray.carlist.size();i++) {//这里必须用size，用100超出范围会报错
			if(st.equals(cararray.carlist.get(i).getCardnum())) {
				  car=cararray.goout(cararray.carlist.get(i));
				  location[i]=0;
				  flag=true;
				break;
			}
		}
		if(flag==false) {
			
			return "抱歉，此车辆不在车库";
		}
	
		return   "入库时间:"+car.getIntime().getDate()
				+"      出库时间:"+car.getOuttime().getDate()+"      "
				+st+"已离开，本次的费用是"+car.getPrice()
				+ "      剩余空闲车位数："+(100-cararray.carlist.size());
	}
	public String  Findcar(String s) {
	
		String st=s;
		boolean flag =false;
		String str =null;
		for(int i=0;i<cararray.carlist.size();i++) {
			if(st.equals(cararray.carlist.get(i).getCardnum())) {
			     str=	"该车停在"+cararray.carlist.get(i).getLocationnum()+"车位"+"   其入库时间为："+cararray.carlist.get(i).getIntime().getDate();
				flag=true;
				break;
			}
		}
		if(flag==false) {
		
			return "此车不在该停车场";
		}
		return str;
		
		
	}

}



